<?php

namespace backend\jobs;

use Yii;
/**
 * Class MailJob.
 */
class MailJob extends \yii\base\BaseObject implements \yii\queue\RetryableJobInterface
{
    public $from;

    public $to;

    public $subject;

    public $body;

    /**
     * @inheritdoc
     */
    public function execute($queue)
    {

        Yii::$app->mailer->compose()
            ->setFrom($this->from)
            ->setTo($this->to)
            ->setSubject($this->subject)
            ->setTextBody($this->body)
            // ->setHtmlBody('<b>HTML content</b>')
            ->send();
    }

    /**
     * @inheritdoc
     */
    public function getTtr()
    {
        return 60;
    }

    /**
     * @inheritdoc
     */
    public function canRetry($attempt, $error)
    {
        return $attempt < 3;
    }
}
